<?php
class MonthView extends Control {
	var $MonthDecorator ;
	var $Month ;
	var $Cal ;
	var $Events ;
	var $cE ;
	var $tableHelper ;
	var $year ;
	var $month ;
	var $DayNames;
	var $firstDay = 1 ; //Monday is frst day of the week
	var $Uri ;
	
	function MonthView ( &$Context ) {
		$this->Name = 'MonthView' ;
		$this->Control ( $Context ) ;
		require_once CALENDAR_ROOT . 'Month/Weekdays.php' ;
		require_once CALENDAR_ROOT . 'Day.php' ;
		require_once CALENDAR_ROOT . 'Decorator.php' ;
		require_once CALENDAR_ROOT . 'Table/Helper.php' ;
		require_once CALENDAR_ROOT . 'Util/Textual.php' ;
		require_once CALENDAR_ROOT . 'Util/Uri.php' ;
		require_once VCAL_ROOT . 'library/Class.DiaryEvent.php' ;
		require_once VCAL_ROOT . 'library/Class.MonthPayload_Decorator.php' ;
		
		//$this->Cal = new Calendar ( ) ;
		//$this->tableHelper = & new Calendar_Table_Helper ( $this->Cal, $this->firstDay ) ;
		$this->Uri = new Calendar_Util_Uri ( 'Year', 'Month' ) ;
		$thisYear = ForceIncomingString ( 'Year', date ( "Y" ) ) ;
		$thisMonth = ForceIncomingString ( 'Month', date ( "m" ) ) ;
		$this->Month = new Calendar_Month_Weekdays ($thisYear, $thisMonth, $this->firstDay ) ;
		$this->MonthDecorator = new MonthPayload_Decorator ( $this->Month ) ;
		$this->DayNames = Calendar_Util_Textual::orderedWeekdays($this->Month,'short');
		$this->GetEventsFromDateRange ( date ( "Y-m-d", mktime ( 0, 0, 0, $thisMonth, 1, $thisYear ) ), date ( "Y-m-d", mktime ( 0, 0, 0, $thisMonth + 1, 0, $thisYear ) ) ) ;
	}
	
	function GetEventsFromDateRange ( $Start , $End ) {
		$EventManager = $this->Context->ObjectFactory->NewContextObject ( $this->Context, 'EventManager' ) ;
		$EventManager->GetEventByDateRange($Start, $End ) ;
		$this->Events = array ( ) ;
		foreach ( $EventManager->Events as $Event ) {
			$this->Events [] = array ( 'Start' => $Event->StartDate . ' ' . $Event->StartTime ,
						'End' => $Event->EndDate . ' ' . $Event->EndTime ,
						'Name' => $Event->Name ,
						'Title' => $Event->Title ,
						'Color' => $Event->ColorArr ,
						'Link' => GetUrl ( $Configuration, 'comments.php', '', 'DiscussionID', $Event->DiscussionID, '', '' ) ) ;
		}
		$this->MonthDecorator->build ( $this->Events ) ;
	}
	
	function Render () {
		include THEME_ROOT . 'Theme.MonthView.php' ;
	}
}
?>
